﻿//
// Description: Lấy thông tin từ File Web.Config
//
using System.Linq;
using System.Configuration;
using System.Collections.Specialized;
using System;

namespace Config
{
    public sealed class SettingSingleton
    {

        #region Process Method
        /// <summary>
        /// Lấy giá trị của Key trong AppSetting
        /// </summary>
        /// <param name="_Key">Key</param>
        /// <returns>Return Null nếu không có key</returns>
        public string GetAppKeyValue(string _Key)
        {
            NameValueCollection appsettings = ConfigurationManager.AppSettings;
            if (appsettings == null) return null;
            if (appsettings.AllKeys.Contains(_Key))
            {
                return appsettings[_Key];
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// Lấy xâu kết nối trong file Web.Config
        /// </summary>
        /// <param name="_Key">key</param>
        /// <returns>Return null nếu không có key</returns>
        public string GetConnectionStringKeyValue(string _Key)
        {
            try
            {
                return ConfigurationManager.ConnectionStrings[_Key].ConnectionString;
            }
            catch { }
            return null;
        }
        #endregion Process Method

        #region Attribute Connection String
        public string ConnectionStringBackend
        {
            get
            {
                return GetConnectionStringKeyValue(Constants.CONNECTION_STRING_BACKEND);
            }
        }

        public string ConnectionStringHiLoGame
        {
            get
            {
                return GetConnectionStringKeyValue(Constants.CONNECTION_STRING_HILOGAME);
            }
        }
        public string ConnectionStringPayment
        {
            get
            {
                return GetConnectionStringKeyValue(Constants.CONNECTION_STRING_PAYMENT);
            }
        }
        #endregion

        #region AppSetting
        public string WEB_ROOT
        {
            get
            {
                return GetAppKeyValue(Constants.WEB_ROOT);
            }
        }

        public string COOKIE_DOMAIN
        {
            get
            {
                return GetAppKeyValue(Constants.COOKIE_DOMAIN);
            }
        }

        /// <summary>
        /// Thời gian hết hạn Cookie
        /// </summary>
        public string COOKIE_EXPIRES
        {
            get
            {
                return GetAppKeyValue(Constants.COOKIE_EXPIRES);
            }
        }

        public string HILO_REDIS
        {
            get
            {
                return GetAppKeyValue(Constants.HILO_REDIS);
            }
        }
        #endregion

        #region Cấu hình kết nối API Go.vn
        public string CLIENT_ID
        {
            get { return GetAppKeyValue(Constants.CLIENT_ID); }
        }
        public string CLIENT_SECRET
        {
            get { return GetAppKeyValue(Constants.CLIENT_SECRET); }
        }
        public string SERVICE_APPID
        {
            get { return GetAppKeyValue(Constants.SERVICE_APPID); }
        }
        public string SERVICE_KEY
        {
            get { return GetAppKeyValue(Constants.SERVICE_KEY); }
        }
        public string MD5_KEY
        {
            get { return GetAppKeyValue(Constants.MD5_KEY); }
        }
        public string MAKER_CODE
        {
            get { return GetAppKeyValue(Constants.MAKER_CODE); }
        }

        public string GET_CODE_URL
        {
            get { return GetAppKeyValue(Constants.GET_CODE_URL); }
        }
        public string GET_PROFILE_URL
        {
            get { return GetAppKeyValue(Constants.GET_PROFILE_URL); }
        }
        public string GET_ACCESSTOKEN_URL
        {
            get { return GetAppKeyValue(Constants.GET_ACCESSTOKEN_URL); }
        }
        public string GET_BLANCE_URL
        {
            get { return GetAppKeyValue(Constants.GET_BLANCE_URL); }
        }
        public string BUYITEMS_URL
        {
            get { return GetAppKeyValue(Constants.BUYITEMS_URL); }
        }
        public string INPUTMONEYBETTING_URL
        {
            get { return GetAppKeyValue(Constants.INPUTMONEYBETTING_URL); }
        }
        public string API_ISTEST
        {
            get { return GetAppKeyValue(Constants.API_ISTEST); }
        }
        #endregion

        #region Cấu hình kết nối API Go su
        public string GOSU_CLIENT_ID
        {
            get { return GetAppKeyValue(Constants.GOSU_CLIENT_ID); }
        }
        public string GOSU_CLIENT_SECRET
        {
            get { return GetAppKeyValue(Constants.GOSU_CLIENT_SECRET); }
        }
        public string GOSU_SERVICE_APPID
        {
            get { return GetAppKeyValue(Constants.GOSU_SERVICE_APPID); }
        }
        public string GOSU_SERVICE_KEY
        {
            get { return GetAppKeyValue(Constants.GOSU_SERVICE_KEY); }
        }
        public string GOSU_RETURN_ACCESSTOKEN_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_RETURN_ACCESSTOKEN_URL); }
        }
        public string GOSU_GRANT_TYPE
        {
            get { return GetAppKeyValue(Constants.GOSU_GRANT_TYPE); }
        }

        public string GOSU_GET_CODE_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_GET_CODE_URL); }
        }
        public string GOSU_GET_PROFILE_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_GET_PROFILE_URL); }
        }
        public string GOSU_GET_ACCESSTOKEN_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_GET_ACCESSTOKEN_URL); }
        }
        public string GOSU_GET_BLANCE_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_GET_BLANCE_URL); }
        }
        public string GOSU_BUYITEMS_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_BUYITEMS_URL); }
        }
        public string GOSU_INPUTMONEYBETTING_URL
        {
            get { return GetAppKeyValue(Constants.GOSU_INPUTMONEYBETTING_URL); }
        }
        public string GOSU_API_ISTEST
        {
            get { return GetAppKeyValue(Constants.API_ISTEST); }
        }
        #endregion
    }
}
